#include<iostream> 
using namespace std;
#define p 10000
int main()
{
	int a[10000] = { 0 }, b[10000] = { 0 };
	int c[20000] = { 0 }, d[20000] = { 0 };
	int x, y;
	int i, j, n, m;
	cin >> n;
	for (i = 0; i < n; i++)
	{
		cin >> x >> y;
		a[y] = x;
	}
	cin >> m;
	for (i = 0; i < m; i++)
	{
		cin >> x >> y;
		b[y] = x;
	}
	for (i = p - 1; i >= 0; i--)
	{
		if (a[i] != 0)
		{
			for (j = 0; j < p; j++)
			{
				if (b[j] != 0)
					c[i + j] += a[i] * b[j];
			}
		}
	}
	int flag = 0;
	for (i = p - 1; i >= 0; i--)
	{
		if (c[i])
		{
			if (flag)
			{
				cout << " ";
			}
			cout << c[i] << " " << i;
			flag++;
		}
	}
	if (!flag)
	{
		cout << "0 0";
	}
	cout << endl;

	for (i = 0; i < p; i++)
	{
		if (a[i] || b[i])
		{
			d[i] = a[i] + b[i];
		}
	}
	flag = 0;
	for (j = p - 1; j >= 0; j--)
	{
		if (d[j] != 0)
		{
			if (flag)
			{
				cout << " ";
			}
			cout << d[j] << " " << j;
			flag++;
		}
	}
	if (!flag)
	{
		cout << "0 0";
	}
}